/*
 * lab10C2.c
 * CSIS 248 Lab #10
 */
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[]){
   char* here;
   const int size_here = 100;
   int status = 0;
   char* sub = "test.dir";

   here = (char*) malloc( size_here );

   if ( getcwd(here, size_here) ) {
     printf("%s: executing in %s\n", argv[0], here);

     status = chdir( sub );

     if (status == 0){
        char* here_now;
        int size_here_now = 0;

        size_here_now = strlen(here) + strlen(sub) + 1;
        here_now = (char*) malloc( size_here_now );
        strncpy( here_now, here, size_here_now );
        strncat( here_now, "/", 1 );
        strncat( here_now, sub, strlen(sub) );
        printf(" %s: now executing in %s\n", argv[0], here_now );
     }
   } else {
      fprintf(stderr, " %s: Unable to get wd.\n", argv[0] );
      return 1;
   }
}
